﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using DataAccess;
using System.Data;

namespace ATM_System_Mock1_G2
{
    public partial class Transfer4 : System.Web.UI.Page
    {
        AccountEntites accountE = new AccountEntites();
        CustomerBL cusB = new CustomerBL();
        CardEntites cardE = new CardEntites();
        LogBL logB = new LogBL();
        LogEntites logE = new LogEntites();
       // AccountEntites a = new AccountEntites();
        protected void Page_Load(object sender, EventArgs e)
        {
            lb_Amount.Text = Session["Amount"].ToString();
            if (!Page.IsPostBack)
            {
                CustomerBL cuB = new CustomerBL();
                DataTable dt = new DataTable();
                accountE.AccountID = int.Parse(Session["AccountReceiveID"].ToString());
                dt = cuB.DiplayAccountReceive(accountE);
                lb_name.Text = dt.Rows[0]["Name"].ToString();
                lb_ID.Text = dt.Rows[0]["AccountID"].ToString();
            }
        }

        public void TransferAccountID()
        {
            try{
                accountE.AccountID = int.Parse(Session["AccountTransferID"].ToString());
                accountE.Balance = int.Parse(lb_Amount.Text);
                cusB.Transfer(accountE);
            }
               
                catch(Exception ex)
            {
                throw ex;
                }
                
            
        }
        public void TransferReceive()
        {
            try {
                accountE.AccountID = int.Parse(Session["AccountReceiveID"].ToString());
                accountE.Balance = int.Parse(lb_Amount.Text);
                cusB.TransferReceive(accountE);

            }
            catch (Exception ex)
            {
                throw ex;
            }
           
        }
        public void WriteLog()
        {
            try {
                logE.LogTypeID = 1;
                logE.ATMID = 2;
                logE.CardNo = Session["CardNo"].ToString();
                logE.LogDate = DateTime.Now;
                logE.Amount = int.Parse(Session["Amount"].ToString());
                logE.Details = "Transfer to " + lb_name.Text;
                logB.writeLog(logE);
            }
            catch (Exception ex)
            {
                throw ex;
            }
           
        }
        public void Transfer()
        {
            TransferAccountID();
            TransferReceive();
            WriteLog();
            Response.Redirect("Transfer5.aspx");
        }
        protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
        {

            Transfer();
            
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("Transfer3.aspx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("Transfer3.aspx");
        }

        protected void Button11_Click(object sender, EventArgs e)
        {
            Transfer();
        }

    }
}